package com.example.basic02;

import java.util.ArrayList;
import java.util.List;

/**
 * @Description
 * @Date 2021/7/17
 * @Created by Jonathan
 */
public class Singleton {
    private static Singleton singleton;
    private List list;

    private Singleton() {
    }

    public void setList(List list) {
        this.list = list;
    }

    public static synchronized Singleton getInstance() {
        if (singleton == null) {
            singleton = new Singleton();
        }
        return singleton;
    }


    public static void main(String[] args) {
        ArrayList<Object> list = new ArrayList<>();
        for (int i = 0; i < 10; i++) {
            Object o = new Object();
            list.add(o);
        }
        Singleton.getInstance().setList(list);
    }
}
